/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.merchant;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.merchant.TimeSlotDao;
import com.neusoft.lohas.modules.ivm.entity.merchant.TimeSlot;

/**
 * 收货时间段Service
 * @author Jackie.Liu
 * @version 2014-10-28
 */
@Component
@Transactional(readOnly = true)
public class TimeSlotService extends BaseService {

	@Autowired
	private TimeSlotDao timeSlotDao;
	
	public TimeSlot get(String id) {
		return timeSlotDao.get(id);
	}
	
	public Page<TimeSlot> find(Page<TimeSlot> page, TimeSlot timeSlot) {
//		String sql = "select t.* from ivm_time_slot t left join ivm_relationship_timeslot_area a on t.id = a.time_id where t.del_flag='0' order by t.sort asc";
//		return timeSlotDao.findBySql(page, sql, TimeSlot.class);
		DetachedCriteria dc = timeSlotDao.createDetachedCriteria();
		dc.add(Restrictions.eq(TimeSlot.FIELD_DEL_FLAG, TimeSlot.DEL_FLAG_NORMAL));
		dc.addOrder(Order.asc("sort"));
		return timeSlotDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(TimeSlot timeSlot) {
		timeSlotDao.save(timeSlot);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		timeSlotDao.deleteById(id);
	}
	
}
